using DG.Tweening;
using System.Collections.Generic;
using UnityEngine;

public class WaveEffect : MonoBehaviour
{
    public float waveHeight { get { return m_WaveHeight; } set { m_WaveHeight = value; } }
    public Color color { get { return m_Color; } set { m_Color = value; } }
    Color m_Color;
    float m_WaveHeight = 1;
    List<SpriteRenderer> m_Waves = new List<SpriteRenderer>();

    bool m_SynColor = true;
    void Start()
    {
        for (int i = 0; i < transform.childCount; ++i)
        {
            var child = transform.GetChild(i);
            var spriteRenderer = child.GetComponent<SpriteRenderer>();
            if (spriteRenderer && spriteRenderer.drawMode == SpriteDrawMode.Sliced)
            {
                m_Waves.Add(spriteRenderer);
            }
        }
    }

    // Update is called once per frame
    void Update()
    {
        foreach (var i in m_Waves)
        {
            var size = i.size;
            size.y = m_WaveHeight;
            i.size = size;
            if (m_SynColor)
            {
                i.color = m_Color;
            }
        }
    }
    public void PlayDamagedEffect()
    {
        m_SynColor = false;
        DOVirtual.DelayedCall(0.5f, () =>
        {
            m_SynColor = true;
        });
        foreach (var i in m_Waves)
        {
            i.color = Color.red;
            i.DOColor(m_Color, 0.5f);
        }
    }
}
